/*
 * @lc app=leetcode.cn id=520 lang=typescript
 *
 * [520] 检测大写字母
 */

// @lc code=start
function detectCapitalUse(word: string): boolean {
    if (word.length === 1) return true;
    const head = word[0];
    const tail = word.split("").slice(1);
    if (isUpperCase(head)) {
        const next = isUpperCase(word[1]);
        // console.log(tail, next);
        return tail.every((i) => next === isUpperCase(i));
    } else {
        return tail.every((i) => !isUpperCase(i));
    }
}

const isUpperCase = (s: string) => {
    if (
        s.charCodeAt(0) >= "A".charCodeAt(0) &&
        s.charCodeAt(0) <= "Z".charCodeAt(0)
    ) {
        return true;
    }
    return false;
};
// @lc code=end
